package com.fgs.common.imageView;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import com.bm.library.PhotoView;

import java.util.List;

/**
 * @author fgs
 * @date 2020/8/28
 * @description
 **/
public class PictureViewPagerAdapter extends PagerAdapter {

    private List<PhotoView> photoViewList;

    public void setPhotoViewList(List<PhotoView> photoViewList) {
        this.photoViewList = photoViewList;
    }

    @Override
    public int getCount() {
        return photoViewList == null ? 0 : photoViewList.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        if (photoViewList != null && position < photoViewList.size()) {
            container.removeView(photoViewList.get(position));
        }
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        if (photoViewList != null && position < photoViewList.size()) {
            container.addView(photoViewList.get(position));
        }
        return photoViewList == null ? null : photoViewList.get(position);
    }
}
